package com.yyk.yykywd.mvvm.view_model

import androidx.lifecycle.MutableLiveData
import com.yyk.yykywd.bean.BaseBean
import com.yyk.yykywd.mvvm.entity.FullContractBean
import com.yyk.yykywd.mvvm.entity.MaterialBean
import com.yyk.yykywd.mvvm.model.GetBase
import com.yyk.yykywd.mvvm.model.MaterialModel
import com.yyk.yykywd.mvvm.model.ReturnMoneyModel
import java.util.ArrayList

/**
 * 文件描述：
 * Created by guo on 2019-12-04.
 */
class MaterialViewModel : BaseViewModel() {
    private var materialModel = MaterialModel()

    var mMaterials: MutableList<MaterialBean.Data> = ArrayList()
    //LiveData,使该数据可以被感知
    var mMaterial = MutableLiveData<MaterialBean>()
    var mDelSuccess = MutableLiveData<BaseBean>()

    fun getMaterials() {
        materialModel.getMaterialList(page.toString(), num.toString(), object : MaterialModel.GetMaterialList {
            override fun getInfo(info: MaterialBean) {
                info.data?.let { mMaterials.addAll(it) }
                mMaterial.value = info
            }

            override fun onError(e: String) {
            }
        })
    }

    fun checkPermission(){
        materialModel.getPermission(object : GetBase {
            override fun getInfo(base: BaseBean) {
                setBaseValue(base)
            }

            override fun onError(e: String) {
            }
        })
    }

    fun delMaterial(id:String) {
        materialModel.delMaterial(id, object : GetBase {
            override fun getInfo(base: BaseBean) {
                mDelSuccess.value = base
            }

            override fun onError(e: String) {
            }
        })
    }
}